package com.bjsxt.chapter11_flyWeight;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ChessFlyWeightFactory
 * @Description 享元工厂类
 * @Author 黑马程序员
 * @Date 15:55 2024/6/22
 * @Version 1.0
 **/
public class ChessFlyWeightFactory {

    // 享元池
    private static Map<String,ChessFlyWeight> map = new HashMap<>();

    public static ChessFlyWeight getChess(String color){
        if (map.get(color) != null){
            return map.get(color);
        }
        ConcreteChessFlyWeight chess = new ConcreteChessFlyWeight(color);
        map.put(color,chess);
        return chess;
    }
}
